using Infrastructure.Attribute;
using ZR.Model;
using ZR.Model.System;
using ZR.Model.System.Dto;
using ZR.ServiceCore.Services.IService;

namespace ZR.ServiceCore.Services
{
    /// <summary>
    /// 报警记录服务实现
    /// </summary>
    [AppService(ServiceType = typeof(IAlarmRecordService), ServiceLifetime = LifeTime.Transient)]
    public class AlarmRecordService : IAlarmRecordService
    {
        private readonly IWindDataPPIService _windDataPPIService;

        public AlarmRecordService(IWindDataPPIService windDataPPIService)
        {
            _windDataPPIService = windDataPPIService;
        }

        /// <summary>
        /// 获取报警记录列表（基于WindDataPPI数据，根据max和min过滤风速）
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <param name="pager">分页参数</param>
        /// <returns></returns>
        public PagedInfo<WindDataPPI> SelectAlarmRecordList(AlarmRecordQueryDto query, PagerInfo pager)
        {
            // 直接调用优化后的WindDataPPI服务，传递风速范围参数
            var windDataQuery = new WindDataPPIQueryDto
            {
                Id = query.Id,
                SourceTable = query.SourceTable,
                XCoordinate = query.XCoordinate,
                YCoordinate = query.YCoordinate,
                WindDirection = query.WindDirection,
                BeginTime = query.BeginTime,
                EndTime = query.EndTime,
                TimeParam = query.TimeParam,
                // 传递风速范围参数，让数据库层面进行过滤
                MaxWindSpeed = query.Max,
                MinWindSpeed = query.Min,
                // 传递新的查询参数
                WindSpeedLike = query.WindSpeedLike,
                XCoordinateMin = query.XCoordinateMin,
                XCoordinateMax = query.XCoordinateMax,
                YCoordinateMin = query.YCoordinateMin,
                YCoordinateMax = query.YCoordinateMax
            };

            // 直接使用分页参数，避免获取大量数据
            return _windDataPPIService.SelectWindDataPPIList(windDataQuery, pager);
        }
    }
}
